import { reactive } from 'vue'
const usePage = (axiosInstance, listKey = 'list') => {
    const pageData = reactive({
        pages: {
            total: 0,
            pageSize: 10,
            currentPage: 1
        },
        data: [],
        formData: {}
    })
    const handleQuery = async () => {
        console.log('handleQuery: ', handleQuery);
        const params = { ...pageData.pages, ...pageData.formData, current: pageData.pages.currentPage }
        delete params.total
        const res = await axiosInstance(params)
        console.log('res: ', res);
        const { [listKey]: list, total } = res || {}
        pageData.data = list || []
        pageData.pages.total = total
    }
    const pageChange = pages => {
        pageData.pages = pages
        handleQuery()
    }
    return {
      pageData,
      handleQuery,
      pageChange
    }
}

export default usePage